#ifndef GAMEPANEL_H
#define GAMEPANEL_H

#include <QMainWindow>
#include"mybutton.h"
#include"buttongroup.h"
#include<QMap>
#include"cardpanel.h"
#include"gamecontrol.h"
#include<QPixmap>
#include<QLabel>
#include<QTimer>
namespace Ui {
class GamePanel;
}

class GamePanel : public QMainWindow
{
    Q_OBJECT

public:
    explicit GamePanel(QWidget *parent = nullptr);
    ~GamePanel();

    //初始化游戏控制类信息
    void GameControlInit();
    //更新分数
    void updatePlayerScore();
    //切割保存
    void initCardMap();
    //裁剪图片
    void cropImage(QPixmap&pix,int x,int y,Card&card);
    //初始化按钮组
    void initBUttonsGroup();

    void initPlayerContext();
    // 初始化游戏场景
    void initGameScene();
    //处理游戏状态
    void gameStatusPrecess(GameControl::GameStatus status);
    //发牌
    void startDispatchCard();
    //扑克牌的移动
    void cardMoveStep(Player*player,int curPos);
    //处理分发得到的扑克牌
    void disPosCard(Player*player,Cards&cards);
    //更新扑克牌在窗口的显示
    void updatePlayerCards(Player*player);
protected:
    void paintEvent(QPaintEvent*ev);

private:
    enum CardAlign{Horizontal, Vertical};
    struct PlayerContext
    {
        //玩家扑克牌显示区域
        QRect cardRect;
        //出牌区域
        QRect playHandRect;
        //扑克牌的对齐方式
        CardAlign align;
        //扑克牌显示正面还是背面
        bool isFrontSide;
        //游戏过程中的提示信息
        QLabel*info;
        //玩家的头像
         QLabel*roleImg;
        //玩家打出的牌
         Cards lastCards;

    };
    Ui::GamePanel *ui;
    QPixmap m_bkImage;
    GameControl*m_gameCtl;
    QVector<Player*>m_playList;
    QMap<Card,CardPanel*> m_cardMap;

    QSize m_cardSize;
    QPixmap m_carBackImg;
    QMap<Player*,PlayerContext>m_contexMap;

    CardPanel*m_baseCard;
    CardPanel*m_moveCard;

    QVector<CardPanel*>m_last3Card;
    QPoint m_baseCardPos;

    GameControl::GameStatus m_gameStatus;
    QTimer*m_timer;


public slots:
    void onDispatchCard();
    void onStartButton();

    //处理玩家状态变化
    void onPlayerStatusChanged(Player*player,GameControl::PlayerStatus status);
    //处理玩家抢地主
    void onGrabLordBet(Player*player,int bet,int flag);

signals:


};

#endif // GAMEPANEL_H
